package ${package}.${moduleName}.dao;

import cn.hutool.core.lang.ObjectId;

import com.querydsl.jpa.impl.JPAQuery;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

@Slf4j
@Repository
public class ${ClassName}RepositoryJPA extends QueryDSLSupport implements ${ClassName}Repository {

    @Override
    public String nextId() {
        return ObjectId.next();
    }

    @Override
    public ${ClassName} ofId(String id) {
        return loadById(${ClassName}.class, id).orElseThrow(NotFoundException::new);
    }


    @Override
    public void save(${ClassName} ${className}) {
        saveOrUpdate(${className});
    }

    @Override
    public PagedResult<${ClassName}> page(Paged paged) {
        JPAQuery<${ClassName}> jpaQuery = selectFrom(${className});
        jpaQuery.offset(paged.getOffset())
                .limit(paged.getSize());
        return new PagedResult<>(jpaQuery.fetch(), paged, jpaQuery.fetchCount());
    }


}